package com.swinboo.im.entity.em;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Swinboo
 * @date 2022-03-19 21:10
 * @description:
 */

/**
 * 息类型；txt:文本消息，img：图片消息，loc：位置消息，audio：语音消息，video：视频消息，file：文件消息
 */
@Getter
public enum
MsgType {

    IMG("IMG", "图片消息", 100),
    TEXT("TEXT", "文本消息", 101),
    LOC("LOC", "位置消息", 102),
    AUDIO("AUDIO", "语音消息", 103),
    VIDEO("VIDEO", "视频消息", 104),
    FILE("FILE", "文件消息", 105),


    ;


    private final String type;
    private final String des;
    private final Integer code;

    MsgType(String type, String des, Integer code) {
        this.type = type;
        this.des = des;
        this.code = code;
    }

    public static MsgType getByType(String type) {
        return Arrays.stream(MsgType.values())
                .filter(msgType -> StringUtils.equals(msgType.getType(), type))
                .findFirst()
                .orElse(null);
    }


    public static MsgType getByCode(Integer code) {
        return Arrays.stream(MsgType.values())
                .filter(msgType -> Objects.equals(code, msgType.code))
                .findFirst()
                .orElse(null);
    }
}
